package com.domespringcloudprovider.controller;

import com.domespringcloudapi.entity.StudentEntity;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class StudentController {
    @GetMapping(path = "/get")
    @HystrixCommand(fallbackMethod = "get2")
    public List<StudentEntity> get() throws Exception{
        List<StudentEntity> list=new ArrayList<StudentEntity>();
        list.add(new StudentEntity("1001","大聪明",5));
        list.add(new StudentEntity("1002","小聪明",5));
        list.add(new StudentEntity("1003","老聪明",5));
        if(list.size()==3){
            throw new Exception("接口出错");

        }  return  list;

    }
    public List<StudentEntity> get2(){
        List<StudentEntity> list=new ArrayList<StudentEntity>();
        list.add(new StudentEntity("1001","出错了",5));
        list.add(new StudentEntity("1002","出错了",5));
        list.add(new StudentEntity("1003","出错了",5));
        return  list;
    }
}
